package cn.com.pc.content.domain.authority;

import cn.com.pc.content.domain.Site;
import cn.com.pc.content.jpa.SiteConverter;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.time.LocalDateTime;

@Entity
@DynamicUpdate
@DynamicInsert
@Table(name = "site_operator_rels")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SiteOperator {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    /**
     * 操作员id
     */
    @Column(name = "operator_id")
    private Long operatorId;

    /**
     * 站点列表
     */
    @Column(name = "site")
    @Convert(converter = SiteConverter.class)
    private Site site;

    /**
     * 逻辑删除
     */
    @Column(name = "deleted")
    private boolean deleted;

    /**
     * 创建时间
     */
    @JsonFormat(timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss", shape = JsonFormat.Shape.STRING)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @Column(name = "created_at")
    private LocalDateTime createdAt;

    /**
     * 创建人id
     */
    @Column(name = "created_user_id")
    private Long createdUserId;

}
